package com.gy.api.pc.content.controller;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import com.gy.api.base.ApiIndex;
import com.gy.api.base.IDsEntity;
import com.gy.api.base.R;
import com.gy.api.base.RestPage;
import com.gy.api.pc.content.domain.vo.PosterAddVO;
import com.gy.api.pc.content.domain.vo.PosterSelectListDto;
import com.gy.api.pc.content.domain.vo.PosterUpdateVO;
import com.gy.api.pc.content.domain.vo.PosterVO;
import com.gy.api.pc.content.service.IPosterService;
import com.gy.api.pc.filings.domain.vo.WcContentExamineListVO;
import com.gy.api.pc.filings.domain.vo.WcContentExamineSearchVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.rmi.ServerException;
import java.util.List;


@Controller
@RequestMapping("/poster")
@Api( tags = ApiIndex.PosterController)
public class PosterController {

    @Autowired
    private IPosterService posterService;

    @ApiOperation("查询专题管理列表")
    @PostMapping("/list")
    @ResponseBody
    public R<RestPage<List<PosterVO>>> list(@ApiParam(value = "查询参数") @RequestBody PosterSelectListDto poster)  {
        List<PosterVO> list = posterService.selectPosterList(poster);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

//    @ApiOperation("导出专题管理列表")
//    @PostMapping("/export")
//    public AjaxResult export(PosterSelectListDto poster) {
//        List<Poster> list = posterService.selectPosterList(poster);
//        ExcelUtil<Poster> util = new ExcelUtil<Poster>(Poster.class);
//        return util.exportExcel(list, "专题管理数据");
//    }

    @ApiOperation("获取专题详情")
    @GetMapping("/selectPosterById")
    @ResponseBody
    public R<PosterVO> selectPosterById(@RequestParam("id") @ApiParam(value = "专题id")  String id) {
        PosterVO poster = posterService.selectPosterById(id);
        return new R(poster);
    }

    @ApiOperation("新增专题管理")
    @PostMapping("/add")
    @ResponseBody
    public R addSave(@RequestBody PosterAddVO addVO) throws ServerException {
        posterService.insertPoster(addVO);
        return new R();
    }

    @ApiOperation("修改专题管理")
    @PostMapping("/edit")
    @ResponseBody
    public R editSave(@RequestBody PosterUpdateVO updateDto) throws ServerException {
        posterService.updatePoster(updateDto);
        return new R();
    }

    @ApiOperation("修改专题启用禁用状态 0=启用,1=禁用")
    @PostMapping("/updateEnable")
    @ResponseBody
    public R updateEnable(@RequestParam("enable")@ApiParam(value = "0=启用,1=禁用")  String enable, @RequestParam("id") @ApiParam(value = "专题id")  String id) throws ServerException {
        posterService.updatePosterEnable(enable,id);
        return new R();
    }

    @ApiOperation("删除专题管理")
    @PostMapping("/remove")
    @ResponseBody
    public R remove(@RequestBody IDsEntity iDsEntity) {
        posterService.deletePosterByIds(iDsEntity.getIds());
        return new R();
    }
}
